/*
 * Packet.h
 *
 *  Created on: Aug 23, 2012
 *      Author: nam20485
 */

#include "Message.h"
#include "Array.h"
#include "LinkedList.h"

#ifndef PACKET_H_
#define PACKET_H_

template <class T>
class Packet
{
public:
	static inline const Packet<T>* FromBytes(const Array<T>& bytes);
	static inline const Packet<T>* FromBytes(const LinkedList<T>& bytes);
	static inline const Packet<T>* FromBytes(const Message& message);
	virtual ~Packet()	{	}

	inline const Message::Header& getHeader()	 const	{ return m_header; }
	inline const Message& getMessage() const	{ return m_message; }

protected:
	Packet(const Message::Header& header, const Message& message)
		: m_header(header)
		, m_message(message)
	{

	}

	const Message::Header m_header;
	const Message m_message;
};

template<class T>
/*static*/ inline const Packet<T>* Packet<T>::FromBytes(const Array<T>& bytes)
{
	// de-serialize header
	// construct header

	// de-serialzie message
	// construct message

	// construct packet
	//return Packet<T>()
}

template<class T>
/*static*/ inline const Packet<T>* Packet<T>::FromBytes(const LinkedList<T>& bytes)
{
	return FromBytes(Array<T>(bytes));
}


#endif /* PACKET_H_ */
